﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SharedCode;
using AdminModule.IndexMarkServiceReference;
using System.Collections.ObjectModel;

namespace AdminModule.ViewModels
{
    public class EditPersonDegreeVM : ViewModelBase
    {
        private IndexMarkServiceClient client = new IndexMarkServiceClient();

        public EditPersonDegreeVM()
        {
            client.GetAdmDegreesCompleted += new EventHandler<GetAdmDegreesCompletedEventArgs>(client_GetAdmDegreesCompleted);
            client.GetAdmPersonsCompleted += new EventHandler<GetAdmPersonsCompletedEventArgs>(client_GetAdmPersonsCompleted);
            base.LoadCompleted += new LoadEventHandler(EditPersonDegreeVM_LoadCompleted);
        }

        public override void Init()
        {
            base.Init();
            this.LoadAdmPersonDegrees();
        }

        void EditPersonDegreeVM_LoadCompleted(object sender, LoadEventArgs e)
        {
            if (e.Type == typeof(AdmDegree))
            {
                client.GetAdmPersonsAsync();
            }
            if (e.Type == typeof(AdmPerson))
            {
                base.RaiseInitCompleted();
            }
        }

        #region Степени
        private ObservableCollection<AdmDegree> degrees = new ObservableCollection<AdmDegree>();
        public ObservableCollection<AdmDegree> AdmDegreeCollection
        {
            get
            {
                return this.degrees;
            }
            set
            {
                this.degrees = value;
            }
        }

        void client_GetAdmDegreesCompleted(object sender, GetAdmDegreesCompletedEventArgs e)
        {
            degrees.Clear();
            foreach (var s in e.Result)
            {
                degrees.Add(s);
            }
            this.LoadCompletedInit(typeof(AdmDegree));
        }

        public void LoadAdmPersonDegrees()
        {
            client.GetAdmDegreesAsync();
        }
        #endregion

        #region Персоны
        private ObservableCollection<AdmPerson> persons = new ObservableCollection<AdmPerson>();
        public ObservableCollection<AdmPerson> AdmPersonsCollection
        {
            get
            {
                return this.persons;
            }
            set
            {
                this.persons = value;
            }
        }

        void client_GetAdmPersonsCompleted(object sender, GetAdmPersonsCompletedEventArgs e)
        {
            persons.Clear();
            foreach (var s in e.Result)
            {
                persons.Add(s);
            }
            this.LoadCompletedInit(typeof(AdmPerson));
        }

        public void LoadAdmPerons()
        {
            client.GetAdmPersonsAsync();
        }
        #endregion
    }
}
